<?php
/**
 * Created by PhpStorm.
 * User: xiaom
 * Date: 2016/11/5
 * Time: 12:57
 */

namespace Api\Model;


use Think\Model\ViewModel;

class FailuresRepairModel extends ViewModel {

    public $viewFields=array(
        'FailuresRepair'=>array('id','name','account','mobile','room_number','description','creation_time','_type'=>'LEFT'),
        'Operator'=>array('title'=>'operator_title','_on'=>'FailuresRepair.operator_id=Operator.id','_type'=>'LEFT'),
        'Building'=>array('title'=>'building_title','_on'=>'FailuresRepair.building_id=Building.id','_type'=>'LEFT'),
        'Campus'=>array('title'=>'campus_title','_on'=>'Building.campus_id=Campus.id','_type'=>'LEFT'),
        'FaultType'=>array('title'=>'fault_type_title','_on'=>'FailuresRepair.fault_type_id=FaultType.id','_type'=>'LEFT'),
        'Orders'=>array('id'=>'order_id','status','user_id','order_time','handle_time','user_comment','admin_comment','_on'=>'FailuresRepair.id=Orders.failures_repair_id','_type'=>'LEFT'),
        'Users'=>array('user_login'=>'admin_name','mobile'=>'admin_mobile','_on'=>'Orders.user_id=Users.id','_type'=>'LEFT'),
    );

    protected $_auto = array (
        array('creation_time','time',3,'function'), // 对update_time字段在更新的时候写入当前时间戳
    );

    //获取简单的用户报修列表
    public function getSimpleList(){
        $result=$this
            ->field('id,account,creation_time,operator_title,fault_type_title,status,admin_name,admin_mobile,admin_comment')
            ->order('creation_time desc')
            ->select();
        return $result;
    }
}